package com.work.dao.impl;

import com.work.bean.Hw;
import com.work.bean.Student;
import com.work.dao.BaseDao;
import com.work.dao.StudentDao;

import java.util.List;

public class StudentDaoImpl extends BaseDao implements StudentDao {
    public Student queryStudentById(Integer id) {
        String sql = "SELECT * FROM t_student WHERE id = ? ";
        return  queryForOne(Student.class,sql,id);
    }

    public List<Student> queryStudent() {
        String sql = "SELECT * FROM t_student  ";
        return  queryForList(Student.class,sql);
    }

    public Student queryStudentByUId(Integer uId) {
        String sql = "SELECT * FROM t_student WHERE uid = ? ";
        return  queryForOne(Student.class,sql,uId);
    }

    public int saveStudent(Student student) {
        String sql = "INSERT INTO `t_student` (`uid`, `sno`, `sname`, `age`, `email`, `qq`, `class_id`) VALUES (?, ?, ?, ?, ?, ?, ?)";
        return update(sql,student.getuId(),student.getsNo(),student.getSname(),student.getAge(),student.getEmail(),student.getQq(),student.getClass_id());
    }

    public int updateStudent(Student student) {
        String sql = "UPDATE t_student SET `uid`=?,`sno`=?,`sname`=?,`age`=?,`email`=?,`qq`=?,`class_id`=? WHERE `id` = ?";
        return update(sql,student.getuId(),student.getsNo(),student.getSname(),student.getAge(),student.getEmail(),student.getQq(),student.getClass_id(),student.getId());
    }

    public int deleteStudent(Integer id) {
        String sql = "DELETE FROM `t_student` WHERE `id` = ?";
        return update(sql, id);
    }

    @Override
    public Student query() {
        String sql = "SELECT * FROM t_student ORDER BY id DESC LIMIT 1 ";
        return  queryForOne(Student.class,sql);
    }
}
